package com.damacheng009.future.alarm.crawler;

import java.util.List;

import org.nutz.http.Header;
import org.nutz.http.Http;
import org.nutz.http.Response;

import com.damacheng009.future.alarm.toolkit.GlobalConfig;
import com.damacheng009.future.alarm.vo.KLineVo;

public abstract class BaseCrawler {

	protected String url;
	
	public abstract List<KLineVo> getKLines(String code);
	
	protected String wget(Header header) {
		for (int i = 0; i < GlobalConfig.HTTP_MAX_TRY; ++i) {
			Response resp = null;
			
			try {
				resp = Http.get(url, header, GlobalConfig.HTTP_TIMEOUT);
			} catch (Exception e) {
				continue;
			}

			if (resp != null) {
				if (resp.getStatus() == 200 && resp.getContent().length() > 200) {
					System.out.println("请求成功:" + url);
					return clean(resp.getContent());
				} else {
					System.err.println("URL NOT 200");
				}
			}
		}

		return null;
	}
	
	protected abstract String clean(String originString);
}
